<template>
  <div class="channel-manage">
      <div class="container">
        <div class="model-title">渠道管理</div>
        <div class="list-box">
            <div class="channel-list">
                <el-table
                  :data="channelList"
                  style="width: 100%">
                  <el-table-column
                    v-for="cell in channelListHeader" :key="cell.prop"
                    :prop="cell.prop"
                    :label="cell.label"
                    :formatter = formatterList
                    >
                  </el-table-column>
                  <el-table-column
                    fixed="right"
                    label="操作"
                    width="80">
                    <template slot-scope="scope">
                      <!-- <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button> -->
                      <el-button type="text" @click="handleEditInfo(scope.row)" size="small">编辑</el-button>
                    </template>
                  </el-table-column>
                </el-table>

              </div>
              <!-- <div class="pages-control">
                  <el-pagination
                    @current-change="handleCurrentChange"
                    :current-page.sync="pages.currentPage"
                    :page-size="pages.page_size"
                    layout="prev, pager, next, jumper"
                    :total="pages.total">
                  </el-pagination>
              </div> -->
        </div>
      </div>
  </div>
</template>

<script>
function formatterTime(value) {//value为13位的时间戳
    function add0(m) {
        return m < 10 ? '0' + m : m
    }
    var time = new Date(parseInt(value));
    var y = time.getFullYear();
    var m = time.getMonth() + 1;
    var d = time.getDate();
    return y + '-' + add0(m) + '-' + add0(d);
}
// 0 表示 T+0 1表示 T+1 2表示 D+0 3表示 D+1
const ChannelType = {
    '0':'T+0 ',
    '1':'T+1 ',
    '2':'D+0 ',
    '3':'D+1 '
}
const ChannelStatus = {
    '0':'关闭',
    '1':'正常使用',
    '2':'试运营'
}
export default {
  name: "channel-manage",
  data() {
    return {
      pages:{
          total:1000,
          page_size:20,
          currentPage:1
      },
      channelList: [],
      channelListHeader: [
        { prop: "name", label: "渠道名字" },
        { prop: "channelTag", label: "渠道标识" },
        { prop: "channelNo", label: "渠道商家标号" },
        { prop: "autoclearing", label: "是否自动清算" },
        { prop: "channelType", label: "通道类型" },
        { prop: "subChannelTag", label: "子渠道标识" },
        { prop: "subName", label: "子渠道名字" },
        { prop: "singleMinLimit", label: "单次最低限额" },
        { prop: "singleMaxLimit", label: "单次最高额度" },
        { prop: "everyDayMaxLimit", label: "单日最高额度" },
        { prop: "minextrafee", label: "成本额外费用" },
        { prop: "startTime", label: "通道开始可以使用的时间" },
        { prop: "endTime", label: "通道结算的时间" },
        { prop: "costRate", label: "成本费率" },
        { prop: "status", label: "通道状态" },
        { prop: "remarks", label: "备注" },
        { prop: "createTime", label: "创建时间" }
      ]
    };
  },
  components: {},
  created() {
    this.queryAllChannel();
  },
  mounted() {},
  methods: {
     handleCurrentChange(value){
       this.queryAllChannel();
     },
    queryAllChannel() {
      const token = sessionStorage.getItem(1);
      const url = `user/channel/queryAllChannel/${token}`;
      this.$Http
        .post(url)
        .then(res => {
          if (res.data.resp_code === "000000") {
            this.channelList = res.data.result;
          } else {
            this.$message(res.data.resp_message);
          }
        })
        .catch(err => {
          this.$message.error("服务器繁忙！获取渠道信息失败！");
        });
    },
    handleEditInfo(row){
      // console.log(row);
      this.$router.push({name:'addChannel',params:{channelInfo:row}});
    },
    formatterList(row, column, cellValue, index) {
      if(column.label === "创建时间"){
         return formatterTime(cellValue);
      }else if(column.label === "通道类型"){
          return ChannelType[cellValue];
      }else if(column.label === "通道状态"){
          return ChannelStatus[cellValue];
      } else{
          return cellValue===null?'--':cellValue;
      }
      // 0:关闭；1：正常使用；2：试运营
    }
  }
};
</script>
<style scoped>
.add-brand {
  box-sizing: border-box;
  padding: 20x;
}
.list-box {
  padding: 20px 10px;
}
</style>